package com.wc.AlgoOJ.LQ1441_管道;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/13 22:58
 * @description http://43.138.190.70:8888/p/LQ1441
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int[] l = new int[N];
    static int[] s = new int[N];
    static int n, len;

    public static void main(String[] args) {
        n = sc.nextInt();
        len = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            l[i] = sc.nextInt();
            s[i] = sc.nextInt();
        }
        long l = 1, r = (int) 2e9;
        while (l < r) {
            long mid = l + r >> 1;
            if (check(mid)) r = mid;
            else l = mid + 1;
        }
        out.println(r);
        out.flush();
    }

    static boolean check(long mid) {
        ArrayList<Pair> segs = new ArrayList<>();

        for (int i = 1; i <= n; i++) {
            if (mid >= s[i]) {
                long left = Math.max(1, l[i] - (mid - s[i]));
                long right = Math.min(len, (long) l[i] + (mid - s[i]));
                segs.add(new Pair(left, right));
            }
        }
        segs.sort(Pair::compareTo);

        long st = -1;
        long ed = -1;
        for (Pair seg : segs) {
            if (ed + 1 < seg.l) {
                st = seg.l;
            }
            ed = Math.max(ed, seg.r);
        }
        return st == 1 && ed == len;
    }

    static class Pair implements Comparable<Pair> {
        long l, r;

        Pair(long l, long r) {
            this.l = l;
            this.r = r;
        }

        @Override
        public int compareTo(Pair o) {
            if (l == o.l) {
                return Long.compare(r, o.r);
            }
            return Long.compare(l, o.l);
        }
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
